package com.snow.it.common.statemachine.job;

import com.snow.it.common.statemachine.yarn.conf.YarnConfiguration;
import com.snow.it.common.statemachine.yarn.event.AsyncDispatcher;
import com.snow.it.common.statemachine.yarn.event.Dispatcher;
import com.snow.it.common.statemachine.yarn.service.CompositeService;
import com.snow.it.common.statemachine.yarn.service.Service;

@SuppressWarnings("unchecked")
public class SimpleMRAppMaster extends CompositeService {
    private Dispatcher dispatcher ; // 中央异步调度器
    private String jobID ;

    public SimpleMRAppMaster(String name , String jobID){
        super(name) ;
        this.jobID = jobID ;
    }

    public void serviceInit(final YarnConfiguration conf) throws Exception{
        dispatcher = new AsyncDispatcher() ; //定义一个中央异步调度器
        //注册状态机处理器
        dispatcher.register(JobEventType.class, new JobStateMachine(jobID,dispatcher.getEventHandler())) ;
        addService((Service)dispatcher) ;
        super.serviceInit(conf) ;
    }

    public Dispatcher getDispatcher(){
        return dispatcher ;
    }
}
